

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="Description" content="scikit-learn: machine learning in Python">

  
  <title>Frequently Asked Questions &mdash; scikit-learn 0.22 documentation</title>
  
  <link rel="canonical" href="http://scikit-learn.org/stable/faq.html" />

  
  <link rel="shortcut icon" href="_static/favicon.ico"/>
  

  <link rel="stylesheet" href="_static/css/vendor/bootstrap.min.css" type="text/css" />
  <link rel="stylesheet" href="_static/gallery.css" type="text/css" />
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script> 
</head>
<body>
<nav id="navbar" class="sk-docs-navbar navbar navbar-expand-md navbar-light bg-light py-0">
  <div class="container-fluid sk-docs-container px-0">
      <a class="navbar-brand py-0" href="index.html">
        <img
          class="sk-brand-img"
          src="_static/scikit-learn-logo-small.png"
          alt="logo"/>
      </a>
    <button
      id="sk-navbar-toggler"
      class="navbar-toggler"
      type="button"
      data-toggle="collapse"
      data-target="#navbarSupportedContent"
      aria-controls="navbarSupportedContent"
      aria-expanded="false"
      aria-label="Toggle navigation"
    >
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="sk-navbar-collapse collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="install.html">Install</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="user_guide.html">User Guide</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="modules/classes.html">API</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="auto_examples/index.html">Examples</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="getting_started.html">Getting Started</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="tutorial/index.html">Tutorial</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="glossary.html">Glossary</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="developers/index.html">Development</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="#">FAQ</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="related_projects.html">Related packages</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="roadmap.html">Roadmap</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="about.html">About us</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="https://github.com/scikit-learn/scikit-learn">GitHub</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="https://scikit-learn.org/dev/versions.html">Other Versions</a>
        </li>
        <li class="nav-item dropdown nav-more-item-dropdown">
          <a class="sk-nav-link nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">More</a>
          <div class="dropdown-menu" aria-labelledby="navbarDropdown">
              <a class="sk-nav-dropdown-item dropdown-item" href="getting_started.html">Getting Started</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="tutorial/index.html">Tutorial</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="glossary.html">Glossary</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="developers/index.html">Development</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="#">FAQ</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="related_projects.html">Related packages</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="roadmap.html">Roadmap</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="about.html">About us</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="https://github.com/scikit-learn/scikit-learn">GitHub</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="https://scikit-learn.org/dev/versions.html">Other Versions</a>
          </div>
        </li>
      </ul>
      <div id="searchbox" role="search">
          <div class="searchformwrapper">
          <form class="search" action="search.html" method="get">
            <input class="sk-search-text-input" type="text" name="q" aria-labelledby="searchlabel" />
            <input class="sk-search-text-btn" type="submit" value="Go" />
          </form>
          </div>
      </div>
    </div>
  </div>
</nav>
<div class="d-flex" id="sk-doc-wrapper">
    <input type="checkbox" name="sk-toggle-checkbox" id="sk-toggle-checkbox">
    <label id="sk-sidemenu-toggle" class="sk-btn-toggle-toc btn sk-btn-primary" for="sk-toggle-checkbox">Toggle Menu</label>
    <div id="sk-sidebar-wrapper" class="border-right">
      <div class="sk-sidebar-toc-wrapper">
        <div class="sk-sidebar-toc-logo">
          <a href="index.html">
            <img
              class="sk-brand-img"
              src="_static/scikit-learn-logo-small.png"
              alt="logo"/>
          </a>
        </div>
        <div class="btn-group w-100 mb-2" role="group" aria-label="rellinks">
            <a href="install.html" role="button" class="btn sk-btn-rellink py-1" sk-rellink-tooltip="Installing scikit-learn">Prev</a><a href="preface.html" role="button" class="btn sk-btn-rellink py-1" sk-rellink-tooltip="Welcome to scikit-learn">Up</a>
            <a href="support.html" role="button" class="btn sk-btn-rellink py-1" sk-rellink-tooltip="Support">Next</a>
        </div>
        <div class="alert alert-danger p-1 mb-2" role="alert">
          <p class="text-center mb-0">
          <strong>scikit-learn 0.22</strong><br/>
          <a href="http://scikit-learn.org/dev/versions.html">Other versions</a>
          </p>
        </div>
        <div class="alert alert-warning p-1 mb-2" role="alert">
          <p class="text-center mb-0">
            Please <a class="font-weight-bold" href="about.html#citing-scikit-learn"><string>cite us</string></a> if you use the software.
          </p>
        </div>
          <div class="sk-sidebar-toc">
            <ul>
<li><a class="reference internal" href="#">Frequently Asked Questions</a><ul>
<li><a class="reference internal" href="#what-is-the-project-name-a-lot-of-people-get-it-wrong">What is the project name (a lot of people get it wrong)?</a></li>
<li><a class="reference internal" href="#how-do-you-pronounce-the-project-name">How do you pronounce the project name?</a></li>
<li><a class="reference internal" href="#why-scikit">Why scikit?</a></li>
<li><a class="reference internal" href="#how-can-i-contribute-to-scikit-learn">How can I contribute to scikit-learn?</a></li>
<li><a class="reference internal" href="#what-s-the-best-way-to-get-help-on-scikit-learn-usage">What’s the best way to get help on scikit-learn usage?</a></li>
<li><a class="reference internal" href="#how-should-i-save-export-or-deploy-estimators-for-production">How should I save, export or deploy estimators for production?</a></li>
<li><a class="reference internal" href="#how-can-i-create-a-bunch-object">How can I create a bunch object?</a></li>
<li><a class="reference internal" href="#how-can-i-load-my-own-datasets-into-a-format-usable-by-scikit-learn">How can I load my own datasets into a format usable by scikit-learn?</a></li>
<li><a class="reference internal" href="#what-are-the-inclusion-criteria-for-new-algorithms">What are the inclusion criteria for new algorithms ?</a></li>
<li><a class="reference internal" href="#why-are-you-so-selective-on-what-algorithms-you-include-in-scikit-learn">Why are you so selective on what algorithms you include in scikit-learn?</a></li>
<li><a class="reference internal" href="#why-did-you-remove-hmms-from-scikit-learn">Why did you remove HMMs from scikit-learn?</a></li>
<li><a class="reference internal" href="#will-you-add-graphical-models-or-sequence-prediction-to-scikit-learn">Will you add graphical models or sequence prediction to scikit-learn?</a></li>
<li><a class="reference internal" href="#will-you-add-gpu-support">Will you add GPU support?</a></li>
<li><a class="reference internal" href="#do-you-support-pypy">Do you support PyPy?</a></li>
<li><a class="reference internal" href="#how-do-i-deal-with-string-data-or-trees-graphs">How do I deal with string data (or trees, graphs…)?</a></li>
<li><a class="reference internal" href="#why-do-i-sometime-get-a-crash-freeze-with-n-jobs-1-under-osx-or-linux">Why do I sometime get a crash/freeze with n_jobs &gt; 1 under OSX or Linux?</a></li>
<li><a class="reference internal" href="#why-does-my-job-use-more-cores-than-specified-with-n-jobs">Why does my job use more cores than specified with n_jobs?</a></li>
<li><a class="reference internal" href="#why-is-there-no-support-for-deep-or-reinforcement-learning-will-there-be-support-for-deep-or-reinforcement-learning-in-scikit-learn">Why is there no support for deep or reinforcement learning / Will there be support for deep or reinforcement learning in scikit-learn?</a></li>
<li><a class="reference internal" href="#why-is-my-pull-request-not-getting-any-attention">Why is my pull request not getting any attention?</a></li>
<li><a class="reference internal" href="#how-do-i-set-a-random-state-for-an-entire-execution">How do I set a <code class="docutils literal notranslate"><span class="pre">random_state</span></code> for an entire execution?</a></li>
<li><a class="reference internal" href="#why-do-categorical-variables-need-preprocessing-in-scikit-learn-compared-to-other-tools">Why do categorical variables need preprocessing in scikit-learn, compared to other tools?</a></li>
<li><a class="reference internal" href="#why-does-scikit-learn-not-directly-work-with-for-example-pandas-dataframe">Why does Scikit-learn not directly work with, for example, pandas.DataFrame?</a></li>
<li><a class="reference internal" href="#do-you-plan-to-implement-transform-for-target-y-in-a-pipeline">Do you plan to implement transform for target y in a pipeline?</a></li>
</ul>
</li>
</ul>

          </div>
      </div>
    </div>
    <div id="sk-page-content-wrapper">
      <div class="sk-page-content container-fluid body px-md-3" role="main">
        
  <div class="section" id="frequently-asked-questions">
<span id="faq"></span><h1>Frequently Asked Questions<a class="headerlink" href="#frequently-asked-questions" title="Permalink to this headline">¶</a></h1>
<p>Here we try to give some answers to questions that regularly pop up on the mailing list.</p>
<div class="section" id="what-is-the-project-name-a-lot-of-people-get-it-wrong">
<h2>What is the project name (a lot of people get it wrong)?<a class="headerlink" href="#what-is-the-project-name-a-lot-of-people-get-it-wrong" title="Permalink to this headline">¶</a></h2>
<p>scikit-learn, but not scikit or SciKit nor sci-kit learn.
Also not scikits.learn or scikits-learn, which were previously used.</p>
</div>
<div class="section" id="how-do-you-pronounce-the-project-name">
<h2>How do you pronounce the project name?<a class="headerlink" href="#how-do-you-pronounce-the-project-name" title="Permalink to this headline">¶</a></h2>
<p>sy-kit learn. sci stands for science!</p>
</div>
<div class="section" id="why-scikit">
<h2>Why scikit?<a class="headerlink" href="#why-scikit" title="Permalink to this headline">¶</a></h2>
<p>There are multiple scikits, which are scientific toolboxes built around SciPy.
You can find a list at <a class="reference external" href="https://scikits.appspot.com/scikits">https://scikits.appspot.com/scikits</a>.
Apart from scikit-learn, another popular one is <a class="reference external" href="https://scikit-image.org/">scikit-image</a>.</p>
</div>
<div class="section" id="how-can-i-contribute-to-scikit-learn">
<h2>How can I contribute to scikit-learn?<a class="headerlink" href="#how-can-i-contribute-to-scikit-learn" title="Permalink to this headline">¶</a></h2>
<p>See <a class="reference internal" href="developers/contributing.html#contributing"><span class="std std-ref">Contributing</span></a>. Before wanting to add a new algorithm, which is
usually a major and lengthy undertaking, it is recommended to start with
<a class="reference internal" href="developers/contributing.html#new-contributors"><span class="std std-ref">known issues</span></a>. Please do not contact the contributors
of scikit-learn directly regarding contributing to scikit-learn.</p>
</div>
<div class="section" id="what-s-the-best-way-to-get-help-on-scikit-learn-usage">
<h2>What’s the best way to get help on scikit-learn usage?<a class="headerlink" href="#what-s-the-best-way-to-get-help-on-scikit-learn-usage" title="Permalink to this headline">¶</a></h2>
<p><strong>For general machine learning questions</strong>, please use
<a class="reference external" href="https://stats.stackexchange.com/">Cross Validated</a> with the <code class="docutils literal notranslate"><span class="pre">[machine-learning]</span></code> tag.</p>
<p><strong>For scikit-learn usage questions</strong>, please use <a class="reference external" href="https://stackoverflow.com/questions/tagged/scikit-learn">Stack Overflow</a>
with the <code class="docutils literal notranslate"><span class="pre">[scikit-learn]</span></code> and <code class="docutils literal notranslate"><span class="pre">[python]</span></code> tags. You can alternatively use the <a class="reference external" href="https://mail.python.org/mailman/listinfo/scikit-learn">mailing list</a>.</p>
<p>Please make sure to include a minimal reproduction code snippet (ideally shorter
than 10 lines) that highlights your problem on a toy dataset (for instance from
<code class="docutils literal notranslate"><span class="pre">sklearn.datasets</span></code> or randomly generated with functions of <code class="docutils literal notranslate"><span class="pre">numpy.random</span></code> with
a fixed random seed). Please remove any line of code that is not necessary to
reproduce your problem.</p>
<p>The problem should be reproducible by simply copy-pasting your code snippet in a Python
shell with scikit-learn installed. Do not forget to include the import statements.</p>
<p>More guidance to write good reproduction code snippets can be found at:</p>
<p><a class="reference external" href="https://stackoverflow.com/help/mcve">https://stackoverflow.com/help/mcve</a></p>
<p>If your problem raises an exception that you do not understand (even after googling it),
please make sure to include the full traceback that you obtain when running the
reproduction script.</p>
<p>For bug reports or feature requests, please make use of the
<a class="reference external" href="https://github.com/scikit-learn/scikit-learn/issues">issue tracker on GitHub</a>.</p>
<p>There is also a <a class="reference external" href="https://gitter.im/scikit-learn/scikit-learn">scikit-learn Gitter channel</a> where some users and developers
might be found.</p>
<p><strong>Please do not email any authors directly to ask for assistance, report bugs,
or for any other issue related to scikit-learn.</strong></p>
</div>
<div class="section" id="how-should-i-save-export-or-deploy-estimators-for-production">
<h2>How should I save, export or deploy estimators for production?<a class="headerlink" href="#how-should-i-save-export-or-deploy-estimators-for-production" title="Permalink to this headline">¶</a></h2>
<p>See <a class="reference internal" href="modules/model_persistence.html#model-persistence"><span class="std std-ref">Model persistence</span></a>.</p>
</div>
<div class="section" id="how-can-i-create-a-bunch-object">
<h2>How can I create a bunch object?<a class="headerlink" href="#how-can-i-create-a-bunch-object" title="Permalink to this headline">¶</a></h2>
<p>Don’t make a bunch object! They are not part of the scikit-learn API. Bunch
objects are just a way to package some numpy arrays. As a scikit-learn user you
only ever need numpy arrays to feed your model with data.</p>
<p>For instance to train a classifier, all you need is a 2D array <code class="docutils literal notranslate"><span class="pre">X</span></code> for the
input variables and a 1D array <code class="docutils literal notranslate"><span class="pre">y</span></code> for the target variables. The array <code class="docutils literal notranslate"><span class="pre">X</span></code>
holds the features as columns and samples as rows . The array <code class="docutils literal notranslate"><span class="pre">y</span></code> contains
integer values to encode the class membership of each sample in <code class="docutils literal notranslate"><span class="pre">X</span></code>.</p>
</div>
<div class="section" id="how-can-i-load-my-own-datasets-into-a-format-usable-by-scikit-learn">
<h2>How can I load my own datasets into a format usable by scikit-learn?<a class="headerlink" href="#how-can-i-load-my-own-datasets-into-a-format-usable-by-scikit-learn" title="Permalink to this headline">¶</a></h2>
<p>Generally, scikit-learn works on any numeric data stored as numpy arrays
or scipy sparse matrices. Other types that are convertible to numeric
arrays such as pandas DataFrame are also acceptable.</p>
<p>For more information on loading your data files into these usable data
structures, please refer to <a class="reference internal" href="datasets/index.html#external-datasets"><span class="std std-ref">loading external datasets</span></a>.</p>
</div>
<div class="section" id="what-are-the-inclusion-criteria-for-new-algorithms">
<span id="new-algorithms-inclusion-criteria"></span><h2>What are the inclusion criteria for new algorithms ?<a class="headerlink" href="#what-are-the-inclusion-criteria-for-new-algorithms" title="Permalink to this headline">¶</a></h2>
<p>We only consider well-established algorithms for inclusion. A rule of thumb is
at least 3 years since publication, 200+ citations and wide use and
usefulness. A technique that provides a clear-cut improvement (e.g. an
enhanced data structure or a more efficient approximation technique) on
a widely-used method will also be considered for inclusion.</p>
<p>From the algorithms or techniques that meet the above criteria, only those
which fit well within the current API of scikit-learn, that is a <code class="docutils literal notranslate"><span class="pre">fit</span></code>,
<code class="docutils literal notranslate"><span class="pre">predict/transform</span></code> interface and ordinarily having input/output that is a
numpy array or sparse matrix, are accepted.</p>
<p>The contributor should support the importance of the proposed addition with
research papers and/or implementations in other similar packages, demonstrate
its usefulness via common use-cases/applications and corroborate performance
improvements, if any, with benchmarks and/or plots. It is expected that the
proposed algorithm should outperform the methods that are already implemented
in scikit-learn at least in some areas.</p>
<p>Inclusion of a new algorithm speeding up an existing model is easier if:</p>
<ul class="simple">
<li><p>it does not introduce new hyper-parameters (as it makes the library
more future-proof),</p></li>
<li><p>it is easy to document clearly when the contribution improves the speed
and when it does not, for instance “when n_features &gt;&gt;
n_samples”,</p></li>
<li><p>benchmarks clearly show a speed up.</p></li>
</ul>
<p>Also note that your implementation need not be in scikit-learn to be used
together with scikit-learn tools. You can implement your favorite algorithm
in a scikit-learn compatible way, upload it to GitHub and let us know. We
will be happy to list it under <a class="reference internal" href="related_projects.html#related-projects"><span class="std std-ref">Related Projects</span></a>. If you already have
a package on GitHub following the scikit-learn API, you may also be
interested to look at <a class="reference external" href="https://scikit-learn-contrib.github.io">scikit-learn-contrib</a>.</p>
</div>
<div class="section" id="why-are-you-so-selective-on-what-algorithms-you-include-in-scikit-learn">
<span id="selectiveness"></span><h2>Why are you so selective on what algorithms you include in scikit-learn?<a class="headerlink" href="#why-are-you-so-selective-on-what-algorithms-you-include-in-scikit-learn" title="Permalink to this headline">¶</a></h2>
<p>Code is maintenance cost, and we need to balance the amount of
code we have with the size of the team (and add to this the fact that
complexity scales non linearly with the number of features).
The package relies on core developers using their free time to
fix bugs, maintain code and review contributions.
Any algorithm that is added needs future attention by the developers,
at which point the original author might long have lost interest.
See also <a class="reference internal" href="#new-algorithms-inclusion-criteria"><span class="std std-ref">What are the inclusion criteria for new algorithms ?</span></a>. For a great read about
long-term maintenance issues in open-source software, look at
<a class="reference external" href="https://www.fordfoundation.org/media/2976/roads-and-bridges-the-unseen-labor-behind-our-digital-infrastructure.pdf#page=8">the Executive Summary of Roads and Bridges</a></p>
</div>
<div class="section" id="why-did-you-remove-hmms-from-scikit-learn">
<h2>Why did you remove HMMs from scikit-learn?<a class="headerlink" href="#why-did-you-remove-hmms-from-scikit-learn" title="Permalink to this headline">¶</a></h2>
<p>See <a class="reference internal" href="#adding-graphical-models"><span class="std std-ref">Will you add graphical models or sequence prediction to scikit-learn?</span></a>.</p>
</div>
<div class="section" id="will-you-add-graphical-models-or-sequence-prediction-to-scikit-learn">
<span id="adding-graphical-models"></span><h2>Will you add graphical models or sequence prediction to scikit-learn?<a class="headerlink" href="#will-you-add-graphical-models-or-sequence-prediction-to-scikit-learn" title="Permalink to this headline">¶</a></h2>
<p>Not in the foreseeable future.
scikit-learn tries to provide a unified API for the basic tasks in machine
learning, with pipelines and meta-algorithms like grid search to tie
everything together. The required concepts, APIs, algorithms and
expertise required for structured learning are different from what
scikit-learn has to offer. If we started doing arbitrary structured
learning, we’d need to redesign the whole package and the project
would likely collapse under its own weight.</p>
<p>There are two project with API similar to scikit-learn that
do structured prediction:</p>
<ul class="simple">
<li><p><a class="reference external" href="https://pystruct.github.io/">pystruct</a> handles general structured
learning (focuses on SSVMs on arbitrary graph structures with
approximate inference; defines the notion of sample as an instance of
the graph structure)</p></li>
<li><p><a class="reference external" href="https://larsmans.github.io/seqlearn/">seqlearn</a> handles sequences only
(focuses on exact inference; has HMMs, but mostly for the sake of
completeness; treats a feature vector as a sample and uses an offset encoding
for the dependencies between feature vectors)</p></li>
</ul>
</div>
<div class="section" id="will-you-add-gpu-support">
<h2>Will you add GPU support?<a class="headerlink" href="#will-you-add-gpu-support" title="Permalink to this headline">¶</a></h2>
<p>No, or at least not in the near future. The main reason is that GPU support
will introduce many software dependencies and introduce platform specific
issues. scikit-learn is designed to be easy to install on a wide variety of
platforms. Outside of neural networks, GPUs don’t play a large role in machine
learning today, and much larger gains in speed can often be achieved by a
careful choice of algorithms.</p>
</div>
<div class="section" id="do-you-support-pypy">
<h2>Do you support PyPy?<a class="headerlink" href="#do-you-support-pypy" title="Permalink to this headline">¶</a></h2>
<p>In case you didn’t know, <a class="reference external" href="https://pypy.org/">PyPy</a> is an alternative
Python implementation with a built-in just-in-time compiler. Experimental
support for PyPy3-v5.10+ has been added, which requires Numpy 1.14.0+,
and scipy 1.1.0+.</p>
</div>
<div class="section" id="how-do-i-deal-with-string-data-or-trees-graphs">
<h2>How do I deal with string data (or trees, graphs…)?<a class="headerlink" href="#how-do-i-deal-with-string-data-or-trees-graphs" title="Permalink to this headline">¶</a></h2>
<p>scikit-learn estimators assume you’ll feed them real-valued feature vectors.
This assumption is hard-coded in pretty much all of the library.
However, you can feed non-numerical inputs to estimators in several ways.</p>
<p>If you have text documents, you can use a term frequency features; see
<a class="reference internal" href="modules/feature_extraction.html#text-feature-extraction"><span class="std std-ref">Text feature extraction</span></a> for the built-in <em>text vectorizers</em>.
For more general feature extraction from any kind of data, see
<a class="reference internal" href="modules/feature_extraction.html#dict-feature-extraction"><span class="std std-ref">Loading features from dicts</span></a> and <a class="reference internal" href="modules/feature_extraction.html#feature-hashing"><span class="std std-ref">Feature hashing</span></a>.</p>
<p>Another common case is when you have non-numerical data and a custom distance
(or similarity) metric on these data. Examples include strings with edit
distance (aka. Levenshtein distance; e.g., DNA or RNA sequences). These can be
encoded as numbers, but doing so is painful and error-prone. Working with
distance metrics on arbitrary data can be done in two ways.</p>
<p>Firstly, many estimators take precomputed distance/similarity matrices, so if
the dataset is not too large, you can compute distances for all pairs of inputs.
If the dataset is large, you can use feature vectors with only one “feature”,
which is an index into a separate data structure, and supply a custom metric
function that looks up the actual data in this data structure. E.g., to use
DBSCAN with Levenshtein distances:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">leven</span> <span class="kn">import</span> <span class="n">levenshtein</span>       
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sklearn.cluster</span> <span class="kn">import</span> <span class="n">dbscan</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;ACCTCCTAGAAG&quot;</span><span class="p">,</span> <span class="s2">&quot;ACCTACTAGAAGTT&quot;</span><span class="p">,</span> <span class="s2">&quot;GAATATTAGGCCGA&quot;</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">lev_metric</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="nb">int</span><span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>     <span class="c1"># extract indices</span>
<span class="gp">... </span>    <span class="k">return</span> <span class="n">levenshtein</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">data</span><span class="p">[</span><span class="n">j</span><span class="p">])</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">))</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span>
<span class="go">array([[0],</span>
<span class="go">       [1],</span>
<span class="go">       [2]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># We need to specify algoritum=&#39;brute&#39; as the default assumes</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># a continuous feature space.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dbscan</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">metric</span><span class="o">=</span><span class="n">lev_metric</span><span class="p">,</span> <span class="n">eps</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">min_samples</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">algorithm</span><span class="o">=</span><span class="s1">&#39;brute&#39;</span><span class="p">)</span>
<span class="gp">... </span>
<span class="go">([0, 1], array([ 0,  0, -1]))</span>
</pre></div>
</div>
<p>(This uses the third-party edit distance package <code class="docutils literal notranslate"><span class="pre">leven</span></code>.)</p>
<p>Similar tricks can be used, with some care, for tree kernels, graph kernels,
etc.</p>
</div>
<div class="section" id="why-do-i-sometime-get-a-crash-freeze-with-n-jobs-1-under-osx-or-linux">
<h2>Why do I sometime get a crash/freeze with n_jobs &gt; 1 under OSX or Linux?<a class="headerlink" href="#why-do-i-sometime-get-a-crash-freeze-with-n-jobs-1-under-osx-or-linux" title="Permalink to this headline">¶</a></h2>
<p>Several scikit-learn tools such as <code class="docutils literal notranslate"><span class="pre">GridSearchCV</span></code> and <code class="docutils literal notranslate"><span class="pre">cross_val_score</span></code>
rely internally on Python’s <code class="docutils literal notranslate"><span class="pre">multiprocessing</span></code> module to parallelize execution
onto several Python processes by passing <code class="docutils literal notranslate"><span class="pre">n_jobs</span> <span class="pre">&gt;</span> <span class="pre">1</span></code> as argument.</p>
<p>The problem is that Python <code class="docutils literal notranslate"><span class="pre">multiprocessing</span></code> does a <code class="docutils literal notranslate"><span class="pre">fork</span></code> system call
without following it with an <code class="docutils literal notranslate"><span class="pre">exec</span></code> system call for performance reasons. Many
libraries like (some versions of) Accelerate / vecLib under OSX, (some versions
of) MKL, the OpenMP runtime of GCC, nvidia’s Cuda (and probably many others),
manage their own internal thread pool. Upon a call to <code class="docutils literal notranslate"><span class="pre">fork</span></code>, the thread pool
state in the child process is corrupted: the thread pool believes it has many
threads while only the main thread state has been forked. It is possible to
change the libraries to make them detect when a fork happens and reinitialize
the thread pool in that case: we did that for OpenBLAS (merged upstream in
master since 0.2.10) and we contributed a <a class="reference external" href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60035">patch</a> to GCC’s OpenMP runtime
(not yet reviewed).</p>
<p>But in the end the real culprit is Python’s <code class="docutils literal notranslate"><span class="pre">multiprocessing</span></code> that does
<code class="docutils literal notranslate"><span class="pre">fork</span></code> without <code class="docutils literal notranslate"><span class="pre">exec</span></code> to reduce the overhead of starting and using new
Python processes for parallel computing. Unfortunately this is a violation of
the POSIX standard and therefore some software editors like Apple refuse to
consider the lack of fork-safety in Accelerate / vecLib as a bug.</p>
<p>In Python 3.4+ it is now possible to configure <code class="docutils literal notranslate"><span class="pre">multiprocessing</span></code> to
use the ‘forkserver’ or ‘spawn’ start methods (instead of the default
‘fork’) to manage the process pools. To work around this issue when
using scikit-learn, you can set the <code class="docutils literal notranslate"><span class="pre">JOBLIB_START_METHOD</span></code> environment
variable to ‘forkserver’. However the user should be aware that using
the ‘forkserver’ method prevents joblib.Parallel to call function
interactively defined in a shell session.</p>
<p>If you have custom code that uses <code class="docutils literal notranslate"><span class="pre">multiprocessing</span></code> directly instead of using
it via joblib you can enable the ‘forkserver’ mode globally for your
program: Insert the following instructions in your main script:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">multiprocessing</span>

<span class="c1"># other imports, custom code, load data, define model...</span>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">multiprocessing</span><span class="o">.</span><span class="n">set_start_method</span><span class="p">(</span><span class="s1">&#39;forkserver&#39;</span><span class="p">)</span>

    <span class="c1"># call scikit-learn utils with n_jobs &gt; 1 here</span>
</pre></div>
</div>
<p>You can find more default on the new start methods in the <a class="reference external" href="https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods">multiprocessing
documentation</a>.</p>
</div>
<div class="section" id="why-does-my-job-use-more-cores-than-specified-with-n-jobs">
<span id="faq-mkl-threading"></span><h2>Why does my job use more cores than specified with n_jobs?<a class="headerlink" href="#why-does-my-job-use-more-cores-than-specified-with-n-jobs" title="Permalink to this headline">¶</a></h2>
<p>This is because <code class="docutils literal notranslate"><span class="pre">n_jobs</span></code> only controls the number of jobs for
routines that are parallelized with <code class="docutils literal notranslate"><span class="pre">joblib</span></code>, but parallel code can come
from other sources:</p>
<ul class="simple">
<li><p>some routines may be parallelized with OpenMP (for code written in C or
Cython).</p></li>
<li><p>scikit-learn relies a lot on numpy, which in turn may rely on numerical
libraries like MKL, OpenBLAS or BLIS which can provide parallel
implementations.</p></li>
</ul>
<p>For more details, please refer to our <a class="reference internal" href="modules/computing.html#parallelism"><span class="std std-ref">Parallelism notes</span></a>.</p>
</div>
<div class="section" id="why-is-there-no-support-for-deep-or-reinforcement-learning-will-there-be-support-for-deep-or-reinforcement-learning-in-scikit-learn">
<h2>Why is there no support for deep or reinforcement learning / Will there be support for deep or reinforcement learning in scikit-learn?<a class="headerlink" href="#why-is-there-no-support-for-deep-or-reinforcement-learning-will-there-be-support-for-deep-or-reinforcement-learning-in-scikit-learn" title="Permalink to this headline">¶</a></h2>
<p>Deep learning and reinforcement learning both require a rich vocabulary to
define an architecture, with deep learning additionally requiring
GPUs for efficient computing. However, neither of these fit within
the design constraints of scikit-learn; as a result, deep learning
and reinforcement learning are currently out of scope for what
scikit-learn seeks to achieve.</p>
<p>You can find more information about addition of gpu support at
<a class="reference internal" href="#will-you-add-gpu-support">Will you add GPU support?</a>.</p>
</div>
<div class="section" id="why-is-my-pull-request-not-getting-any-attention">
<h2>Why is my pull request not getting any attention?<a class="headerlink" href="#why-is-my-pull-request-not-getting-any-attention" title="Permalink to this headline">¶</a></h2>
<p>The scikit-learn review process takes a significant amount of time, and
contributors should not be discouraged by a lack of activity or review on
their pull request. We care a lot about getting things right
the first time, as maintenance and later change comes at a high cost.
We rarely release any “experimental” code, so all of our contributions
will be subject to high use immediately and should be of the highest
quality possible initially.</p>
<p>Beyond that, scikit-learn is limited in its reviewing bandwidth; many of the
reviewers and core developers are working on scikit-learn on their own time.
If a review of your pull request comes slowly, it is likely because the
reviewers are busy. We ask for your understanding and request that you
not close your pull request or discontinue your work solely because of
this reason.</p>
</div>
<div class="section" id="how-do-i-set-a-random-state-for-an-entire-execution">
<h2>How do I set a <code class="docutils literal notranslate"><span class="pre">random_state</span></code> for an entire execution?<a class="headerlink" href="#how-do-i-set-a-random-state-for-an-entire-execution" title="Permalink to this headline">¶</a></h2>
<p>For testing and replicability, it is often important to have the entire execution
controlled by a single seed for the pseudo-random number generator used in
algorithms that have a randomized component. Scikit-learn does not use its own
global random state; whenever a RandomState instance or an integer random seed
is not provided as an argument, it relies on the numpy global random state,
which can be set using <code class="xref py py-func docutils literal notranslate"><span class="pre">numpy.random.seed</span></code>.
For example, to set an execution’s numpy global random state to 42, one could
execute the following in his or her script:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">42</span><span class="p">)</span>
</pre></div>
</div>
<p>However, a global random state is prone to modification by other code during
execution. Thus, the only way to ensure replicability is to pass <code class="docutils literal notranslate"><span class="pre">RandomState</span></code>
instances everywhere and ensure that both estimators and cross-validation
splitters have their <code class="docutils literal notranslate"><span class="pre">random_state</span></code> parameter set.</p>
</div>
<div class="section" id="why-do-categorical-variables-need-preprocessing-in-scikit-learn-compared-to-other-tools">
<h2>Why do categorical variables need preprocessing in scikit-learn, compared to other tools?<a class="headerlink" href="#why-do-categorical-variables-need-preprocessing-in-scikit-learn-compared-to-other-tools" title="Permalink to this headline">¶</a></h2>
<p>Most of scikit-learn assumes data is in NumPy arrays or SciPy sparse matrices
of a single numeric dtype. These do not explicitly represent categorical
variables at present. Thus, unlike R’s data.frames or pandas.DataFrame, we
require explicit conversion of categorical features to numeric values, as
discussed in <a class="reference internal" href="modules/preprocessing.html#preprocessing-categorical-features"><span class="std std-ref">Encoding categorical features</span></a>.
See also <a class="reference internal" href="auto_examples/compose/plot_column_transformer_mixed_types.html#sphx-glr-auto-examples-compose-plot-column-transformer-mixed-types-py"><span class="std std-ref">Column Transformer with Mixed Types</span></a> for an
example of working with heterogeneous (e.g. categorical and numeric) data.</p>
</div>
<div class="section" id="why-does-scikit-learn-not-directly-work-with-for-example-pandas-dataframe">
<h2>Why does Scikit-learn not directly work with, for example, pandas.DataFrame?<a class="headerlink" href="#why-does-scikit-learn-not-directly-work-with-for-example-pandas-dataframe" title="Permalink to this headline">¶</a></h2>
<p>The homogeneous NumPy and SciPy data objects currently expected are most
efficient to process for most operations. Extensive work would also be needed
to support Pandas categorical types. Restricting input to homogeneous
types therefore reduces maintenance cost and encourages usage of efficient
data structures.</p>
</div>
<div class="section" id="do-you-plan-to-implement-transform-for-target-y-in-a-pipeline">
<h2>Do you plan to implement transform for target y in a pipeline?<a class="headerlink" href="#do-you-plan-to-implement-transform-for-target-y-in-a-pipeline" title="Permalink to this headline">¶</a></h2>
<p>Currently transform only works for features X in a pipeline.
There’s a long-standing discussion about
not being able to transform y in a pipeline.
Follow on github issue
<a class="reference external" href="https://github.com/scikit-learn/scikit-learn/issues/4143">#4143</a>.
Meanwhile check out
<a class="reference internal" href="modules/generated/sklearn.compose.TransformedTargetRegressor.html#sklearn.compose.TransformedTargetRegressor" title="sklearn.compose.TransformedTargetRegressor"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.compose.TransformedTargetRegressor</span></code></a>,
<a class="reference external" href="https://github.com/mcasl/PipeGraph">pipegraph</a>,
<a class="reference external" href="https://github.com/scikit-learn-contrib/imbalanced-learn">imbalanced-learn</a>.
Note that Scikit-learn solved for the case where y
has an invertible transformation applied before training
and inverted after prediction. Scikit-learn intends to solve for
use cases where y should be transformed at training time
and not at test time, for resampling and similar uses,
like at imbalanced learn.
In general, these use cases can be solved
with a custom meta estimator rather than a Pipeline</p>
</div>
</div>


      </div>
    <div class="container">
      <footer class="sk-content-footer">
            &copy; 2007 - 2019, scikit-learn developers (BSD License).
          <a href="_sources/faq.rst.txt" rel="nofollow">Show this page source</a>
      </footer>
    </div>
  </div>
</div>
<script src="_static/js/vendor/bootstrap.min.js"></script>

<script>
    window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
    ga('create', 'UA-22606712-2', 'auto');
    ga('set', 'anonymizeIp', true);
    ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>


<script>
$(document).ready(function() {
    /* Add a [>>>] button on the top-right corner of code samples to hide
     * the >>> and ... prompts and the output and thus make the code
     * copyable. */
    var div = $('.highlight-python .highlight,' +
                '.highlight-python3 .highlight,' +
                '.highlight-pycon .highlight,' +
		'.highlight-default .highlight')
    var pre = div.find('pre');

    // get the styles from the current theme
    pre.parent().parent().css('position', 'relative');
    var hide_text = 'Hide prompts and outputs';
    var show_text = 'Show prompts and outputs';

    // create and add the button to all the code blocks that contain >>>
    div.each(function(index) {
        var jthis = $(this);
        if (jthis.find('.gp').length > 0) {
            var button = $('<span class="copybutton">&gt;&gt;&gt;</span>');
            button.attr('title', hide_text);
            button.data('hidden', 'false');
            jthis.prepend(button);
        }
        // tracebacks (.gt) contain bare text elements that need to be
        // wrapped in a span to work with .nextUntil() (see later)
        jthis.find('pre:has(.gt)').contents().filter(function() {
            return ((this.nodeType == 3) && (this.data.trim().length > 0));
        }).wrap('<span>');
    });

    // define the behavior of the button when it's clicked
    $('.copybutton').click(function(e){
        e.preventDefault();
        var button = $(this);
        if (button.data('hidden') === 'false') {
            // hide the code output
            button.parent().find('.go, .gp, .gt').hide();
            button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'hidden');
            button.css('text-decoration', 'line-through');
            button.attr('title', show_text);
            button.data('hidden', 'true');
        } else {
            // show the code output
            button.parent().find('.go, .gp, .gt').show();
            button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'visible');
            button.css('text-decoration', 'none');
            button.attr('title', hide_text);
            button.data('hidden', 'false');
        }
    });

	/*** Add permalink buttons next to glossary terms ***/
	$('dl.glossary > dt[id]').append(function() {
		return ('<a class="headerlink" href="#' +
			    this.getAttribute('id') +
			    '" title="Permalink to this term">¶</a>');
	});
  /*** Hide navbar when scrolling down ***/
  // Returns true when headerlink target matches hash in url
  (function() {
    hashTargetOnTop = function() {
        var hash = window.location.hash;
        if ( hash.length < 2 ) { return false; }

        var target = document.getElementById( hash.slice(1) );
        if ( target === null ) { return false; }

        var top = target.getBoundingClientRect().top;
        return (top < 2) && (top > -2);
    };

    // Hide navbar on load if hash target is on top
    var navBar = document.getElementById("navbar");
    var navBarToggler = document.getElementById("sk-navbar-toggler");
    var navBarHeightHidden = "-" + navBar.getBoundingClientRect().height + "px";
    var $window = $(window);

    hideNavBar = function() {
        navBar.style.top = navBarHeightHidden;
    };

    showNavBar = function() {
        navBar.style.top = "0";
    }

    if (hashTargetOnTop()) {
        hideNavBar()
    }

    var prevScrollpos = window.pageYOffset;
    hideOnScroll = function(lastScrollTop) {
        if (($window.width() < 768) && (navBarToggler.getAttribute("aria-expanded") === 'true')) {
            return;
        }
        if (lastScrollTop > 2 && (prevScrollpos <= lastScrollTop) || hashTargetOnTop()){
            hideNavBar()
        } else {
            showNavBar()
        }
        prevScrollpos = lastScrollTop;
    };

    /*** high preformance scroll event listener***/
    var raf = window.requestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        window.oRequestAnimationFrame;
    var lastScrollTop = $window.scrollTop();

    if (raf) {
        loop();
    }

    function loop() {
        var scrollTop = $window.scrollTop();
        if (lastScrollTop === scrollTop) {
            raf(loop);
            return;
        } else {
            lastScrollTop = scrollTop;
            hideOnScroll(lastScrollTop);
            raf(loop);
        }
    }
  })();
});

</script>
    
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
    
</body>
</html>